#pragma once


namespace MyStack_Queue
{
	

	template<class T, class Container = deque<T>>
	class queue
	{
	public:
		void push(const T& x)
		{
			_con.push_back(x);
		}

		void pop()
		{
			_con.pop_front();
		}

		/*T& top()
		{
			return _con.front();
		}*/

		T& front()
		{
			return _con.front();
		}

		T& back()
		{
			return _con.back();
		}

		size_t size()
		{
			return _con.size();
		}

		bool empty()
		{
			return _con.empty();
		}
	private:
		Container _con;
	};

	/*template<class T>
	class less
	{
	public:
		bool operator()(const T& a, const T& b)
		{
			return a > b;
		}
	};

	template<class T>
	class greater
	{
	public:
		bool operator()(const T& a, const T& b)
		{
			return a < b;
		}
	};*/

	template<class T>
	class less
	{
	public:
		bool operator()(const T& a, const T& b)
		{
			return a < b;
		}
	};

	template<class T>
	class greater
	{
	public:
		bool operator()(const T& a, const T& b)
		{
			return a > b;
		}
	};


	template<class T, class Container = vector<T>, class Compare = less<T>>
	class priority_queue
	{
	public:
		/*void AdjustUp(Container con, int pos)
		{
			int child = pos;
			int parent = (child - 1) / 2;
			while (child > 0)
			{
				if (child + 1 < (int)con.size() && con[child] < con[child + 1])
				{
					++child;
				}
				if (con[child] > con[parent])
				{
					swap(con[child], con[parent]);
				}
				else
				{
					break;
				}
			}
		}*/

		void AdjustUp(int child)
		{
			int parent = (child - 1) / 2;
			Compare com;
			while (child > 0)
			{
				
				if (com(_con[parent], _con[child]))
				{
					swap(_con[child], _con[parent]);
					child = parent;
					parent = (child - 1) / 2;
				}
				else
				{
					break;
				}
			}
		}

		void push(const T& x)
		{
			_con.push_back(x);
			
			AdjustUp(_con.size() - 1);
		}

		void AdjustDown(int parent)
		{
			int child = parent * 2 + 1;
			Compare com;
			while (child < _con.size())
			{
				/*bool operator()(const T & a, const T & b)
				{
					return a > b;
				}*/
				if (child + 1 < _con.size() && com(_con[child], _con[child + 1]))
				{
					++child;
				}
				if (com(_con[parent], _con[child]))
				{
					swap(_con[parent], _con[child]);
					parent = child;
				}
				else
				{
					break;
				}
			}
		}

		void pop()
		{
			swap(_con[0], _con[_con.size() - 1]);
			_con.pop_back();
			AdjustDown(0);
		}

		T& top()
		{
			return _con[0];
		}

		bool empty()
		{
			return _con.empty();
		}

	private:
		Container _con;
	};
	
}